import requests


class IHRMAPI:
    #封装对象接口
    @classmethod
    def ihrm_login_api(cls,login_body):
        login_url="http://ihrm2-test.itheima.net/api/sys/login"
        login_header={"Content-Type": "application/json"}
        login_resp=requests.post(url=login_url,headers=login_header,json=login_body)
        return login_resp

    #封装添加员工
    @classmethod
    def ihrm_add_emp(cls,token,add_body):
        add_url = "http://ihrm2-test.itheima.net/api/sys/user"
        add_header = {"Content-Type": "application/json", "Authorization": token}
        add_resp = requests.post(url=add_url, headers=add_header, json=add_body)
        return add_resp

    #封装查询员工
    @classmethod
    def ihrm_query_emp(cls,emp_id,token):
        query_url = " http://ihrm2-test.itheima.net/api/sys/user/"+emp_id
        query_header = {"Authorization": token}
        query_resp = requests.get(url=query_url, headers=query_header)
        return query_resp

    #封装修改员工
    @classmethod
    def ihrm_modify_emp(cls,emp_id,token,modify_body):
        modify_url = "http://ihrm2-test.itheima.net/api/sys/user/"+emp_id
        modify_header = {"Content-Type": "application/json", "Authorization": token}
        modify_resp = requests.put(url=modify_url, headers=modify_header, json=modify_body)
        return modify_resp

    #封装删除员工
    @classmethod
    def ihrm_del_emp(cls,emp_id,token):
        del_url = "http://ihrm2-test.itheima.net/api/sys/user/"+emp_id
        del_header = {"Authorization": token}
        del_resp = requests.delete(url=del_url, headers=del_header)
        return del_resp

if __name__ == '__main__':
    token='90f3f34b-441d-4cd6-9f65-6a7c806a65a9'
    add_body={
    "username": "小猪佩奇",
    "mobile": "15919658145",
    "workNumber": "22"
}
    print(IHRMAPI.ihrm_add_emp(token,add_body).json())



